package com.jiaai.web.zfp_back.system;


import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.system.api.IUserApi;
import com.jiaai.util.RestResultGenerator;
import com.jiaai.util.logaop.LogAnno;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * class_name:ZBUserController
 * describe:TODO
 * create_user:张昉平
 * create_date:2017/12/21
 * create_date:12:50
 */
@RestController
@RequestMapping("/api/v1/admin")
public class ZBUserController {


    @Reference
    private IUserApi iUserApi;

    @PostMapping("/login")
    @LogAnno(methodName = "管理员登录", methodType = 0)
    public Object login(@RequestParam String loginname, @RequestParam String password){
        try {

            return RestResultGenerator.genSuccessResult(iUserApi.login(loginname, password));
        }catch (Exception e){
            switch (e.getMessage()){
                case "NOUSER":
                    return RestResultGenerator.genErrorResult("没有该用户哦!");
                case "ERRORPWD":
                    return RestResultGenerator.genErrorResult("密码错误哦!");
                    default:
                        throw new RuntimeException("服务器挂了!");
            }
        }
    }

    @PostMapping("/update")
    public Object update(String loginname, String password, String nickname){
        iUserApi.update(loginname, password, nickname);
        return RestResultGenerator.genSuccessResult("成功");
    }
}
